$N.databaseSet.PersonProfileTable = (function ($N) {    
    function init() {
    	var tableName = "PersonProfile";
    	var fields = new Array("personID varchar(50),\
    														name varchar(50), \
                                age int,\
                                allergy varchar(50),\
                                height double,	\
                                weight double,\
                                imageFileName varchar(50),\
                                qq varchar(50),\
                                sex varchar(50),\
                                manualInput int,\
                                sinaWeiBo varchar(50),\
                                created datetime,\
                                modified datetime,\
                                disease varchar(50), \
                                active int,\
                                life varchar(30),\
                                eat varchar(30),\
                                issues varchar(30),\
                                birthDay int,\
                                birthMonth int,\
                                birthYear int,\
                                invitedCode varchar(10),\
                                sharelist varchar(100)");

    	$N.databaseSet.createTableWithPrimaryKey(tableName, fields, "id", function () {
    		console.log("PersonProfileTable is created successfully");
    	});
    }

	function showPersonProfile() {
		/*
		personProfiles.push(personProfile);
		var item = '<li><a href="#healthInputDataList"><img src="images/img2.jpg" />' + personProfile.name + '</a></li>';
		$("#personsImageList").append($.create(item));
		$("li").bind("click", function(){
		selectedIndex = $(this).index();
		});
		 */
		console.log("showPersonProfile : enter");
	}

	function getPersonProfileCallback(tx, result) {
		console.log("get data successfully" + result);
		if (result.rows.length != 0) {
			personProfile = result.rows.item(0);
			showPersonProfile();
		} else {
			console.log("getPersonProfile : no item was selected");
			downloadPersonProfile(personID);
		}
	}
    
    function addPersonProfile(data, successCallback, errorCallback) {
        var sqlCommand =  "INSERT INTO PersonProfile " + "(personID, name, age, allergy, height, weight, imageFileName, qq, \
								sex, manualInput, sinaWeiBo, created, modified, disease,active, life,\
								eat,issues, birthDay, birthMonth ,birthYear, invitedCode, sharelist) \
						        values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        var sqlValueArray =new Array(data.personID, data.name, parseInt(data.age), data.allergy, parseFloat(data.heigth), parseFloat(data.weigth), data.imageFileName,
                     data.qq, data.sex, data.manualinput, data.sinaWeibo, data.created, data.modified, data.disease, parseInt(data.active),
                     data.life, data.eat, data.issues, parseInt(data.birthDay), parseInt(data.birthMonth), data.birthYear, data.invitedCode || 0, data.sharelist
                    );
        $N.databaseSet.executeSQL($N.databaseSet.db, sqlCommand, sqlValueArray, successCallback, errorCallback);
    }

	function getPersonProfile(personID, successCallback, failCallback) {
		var db = $N.databaseSet.db;
		var sqlCommand = "SELECT * FROM PersonProfile WHERE personID = ?";
		$N.databaseSet.executeSQL(db, sqlCommand, [personID], successCallback, failCallback);
	}
	
	function deletePersonProfile(personID, successCallback, failCallback) {
		var db = $N.databaseSet.db;
		var sqlCommand = "DELETE FROM PersonProfile WHERE personID = ?"; 
		$N.databaseSet.executeSQL(db, sqlCommand, [personID], successCallback, null);
	}
/*	
	function clonePersonProfileObject(obj) {
	    var cloneOne = {};
	    cloneOne.personID = obj.personID;
	    cloneOne.
	}
*/    
	return {
        init:              init,
        getPersonProfile : getPersonProfile,
        addPersonProfile : addPersonProfile,
        deletePersonProfile: deletePersonProfile,
     
	}
}
	($N));